package com.fox.contrller;

import com.fox.domain.ResponseResult;
import com.fox.domain.dto.AddArticleDto;
import com.fox.domain.dto.ArticleDto;
import com.fox.domain.entity.Article;
import com.fox.domain.vo.PageVo;
import com.fox.domain.vo.SysArticleVo;
import com.fox.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto articleDto) {
        return articleService.add(articleDto);
    }

    @GetMapping("/list")
    public ResponseResult list(Article article, Integer pageSize, Integer pageNum) {
        PageVo pageVo = articleService.selectArticlePage(article,pageSize,pageNum);
        return ResponseResult.okResult(pageVo);
    }

    @GetMapping("/{id}")
    public ResponseResult getInfo(@PathVariable Long id) {
        SysArticleVo sysArticleVo = articleService.getInfo(id);
        return ResponseResult.okResult(sysArticleVo);
    }
    @PutMapping
    public ResponseResult edit(@RequestBody ArticleDto articleDto) {
        articleService.edit(articleDto);
        return ResponseResult.okResult();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        articleService.removeById(id);
        return ResponseResult.okResult();
    }

}
